package com.ruoyi.system.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.zzw.TEventManage;
import com.ruoyi.common.core.domain.zzw.VO.ManageByPeoIdRecentlyVO;
import com.ruoyi.common.core.domain.zzw.VO.CategoryCountVO;
import com.ruoyi.common.core.page.PageDomain;
import com.ruoyi.common.core.page.TableSupport;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.vo.CountVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.TEventManageMapper;
import com.ruoyi.system.service.ITEventManageService;

/**
 * 【请填写功能名称】Service业务层处理
 *
 * @author xbx
 * @date 2023-10-20
 */
@Service
public class TEventManageServiceImpl extends ServiceImpl<TEventManageMapper, TEventManage> implements ITEventManageService {
    @Autowired
    private TEventManageMapper tEventManageMapper;

    /**
     * 查询【请填写功能名称】
     *
     * @param cEventId 【请填写功能名称】主键
     * @return 【请填写功能名称】
     */
    @Override
    public TEventManage selectTEventManageByCEventId(Long cEventId) {
        return tEventManageMapper.selectTEventManageByCEventId(cEventId);
    }

    /**
     * 查询【请填写功能名称】列表
     *
     * @param tEventManage 【请填写功能名称】
     * @return 【请填写功能名称】
     */
    @Override
    public List<TEventManage> selectTEventManageList(TEventManage tEventManage) {
        return tEventManageMapper.selectTEventManageList(tEventManage);
    }

    /**
     * 新增【请填写功能名称】
     *
     * @param tEventManage 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int insertTEventManage(TEventManage tEventManage) {
        return tEventManageMapper.insertTEventManage(tEventManage);
    }

    /**
     * 修改【请填写功能名称】
     *
     * @param tEventManage 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int updateTEventManage(TEventManage tEventManage) {
        return tEventManageMapper.updateTEventManage(tEventManage);
    }

    /**
     * 批量删除【请填写功能名称】
     *
     * @param cEventIds 需要删除的【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteTEventManageByCEventIds(List<Long> cEventIds) {
        return tEventManageMapper.deleteTEventManageByCEventIds(cEventIds);
    }

    /**
     * 删除【请填写功能名称】信息
     *
     * @param cEventId 【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteTEventManageByCEventId(Long cEventId) {
        return tEventManageMapper.deleteTEventManageByCEventId(cEventId);
    }

    @Override
    public List<TEventManage> listTop3ByType(String type) {
        QueryWrapper<TEventManage> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(StringUtils.isNotBlank(type), TEventManage::getcEventType, type)
                .eq(TEventManage::getCEventClassify,1)
                .orderByDesc(TEventManage::getcEventTime)
                .last("limit 3")
        ;
        return this.list(queryWrapper);
    }

    @Override
    public List<TEventManage> listByRegion(Long districtId) {
        QueryWrapper<TEventManage> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(null != districtId, TEventManage::getcEventDistrictId, districtId)
                .eq(TEventManage::getCEventClassify,1)
        ;
        return this.list(queryWrapper);
    }

    @Override
    public List<TEventManage> manageByPeoId(Integer id) {

        return tEventManageMapper.manageByPeoId(id);
    }

    @Override
    public List<ManageByPeoIdRecentlyVO> manageByPeoIdRecently(Integer id) {
        return tEventManageMapper.manageByPeoIdRecently(id);
    }

    @Override
    public List<CountVO> groupByType() {
        return tEventManageMapper.groupByType();
    }

    @Override
    public Page<TEventManage> pageEvent(String districtId) {
        PageDomain pageDomain = TableSupport.buildPageRequest();
        Integer pageNum = pageDomain.getPageNum();
        Integer pageSize = pageDomain.getPageSize();
        QueryWrapper<TEventManage> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda()
                .eq(null != districtId, TEventManage::getcEventDistrictId, districtId)
                .eq(TEventManage::getCEventClassify,1);
        return this.page(new Page<>(pageNum, pageSize), queryWrapper);
    }


    @Override
    public Page<TEventManage> Event(String districtId) {
        PageDomain pageDomain = TableSupport.buildPageRequest();
        Integer pageNum = pageDomain.getPageNum();
        int pageSize = 100;
        QueryWrapper<TEventManage> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda()
                .eq(null != districtId, TEventManage::getcEventDistrictId, districtId)
                .eq(TEventManage::getCEventClassify,0);
        return this.page(new Page<>(pageNum, pageSize), queryWrapper);
    }

    @Override
    public AjaxResult categoryCount() {
        CategoryCountVO vo=tEventManageMapper.categoryCount();
        return AjaxResult.success(vo);
    }
}
